package com.wswy.wyjk.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

/**
 * 练习参数
 */
public class PracticeType implements Parcelable {

    /**
     * 顺序练习
     */
    public static final int TYPE_ORDER = 0;
    /**
     * 随机练习
     */
    public static final int TYPE_RANDOM = 1;
    /**
     * 章节练习
     */
    public static final int TYPE_CHAPTER = 2;

    /**
     * 难题攻克
     */
    public static final int TYPE_DIFFICULTY = 3;

    /**
     * 未做练习
     */
    public static final int TYPE_UNDONE = 4;

    /**
     * 模拟考试
     */
    public static final int TYPE_EXAM = 5;

    /**
     * 看模拟考试的错题
     */
    public static final int TYPE_EXAM_WRONG_LIST = 6;


    /**
     *  错题
     */
    public static final int TYPE_ERROR = 10;

    public @NonNull
    LicenseType licenseType;

    public @NonNull
    SubjectType subjectType;

    /**
     * 地区
     */
    public String areaCode;

    /**
     * 练习类型
     */
    public int type = TYPE_ORDER;

    /**
     * 章节id 章节练习模式使用
     */
    public long chapterId;

    public String sql;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt( this.licenseType.ordinal());
        dest.writeInt( this.subjectType.ordinal());
        dest.writeString(this.areaCode);
        dest.writeInt(this.type);
        dest.writeLong(this.chapterId);
    }

    public PracticeType() {
    }

    protected PracticeType(Parcel in) {
        int tmpLicenseType = in.readInt();
        this.licenseType = LicenseType.values()[tmpLicenseType];
        int tmpSubjectType = in.readInt();
        this.subjectType = SubjectType.values()[tmpSubjectType];
        this.areaCode = in.readString();
        this.type = in.readInt();
        this.chapterId = in.readLong();
    }

    public static final Parcelable.Creator<PracticeType> CREATOR = new Parcelable.Creator<PracticeType>() {
        @Override
        public PracticeType createFromParcel(Parcel source) {
            return new PracticeType(source);
        }

        @Override
        public PracticeType[] newArray(int size) {
            return new PracticeType[size];
        }
    };


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PracticeType that = (PracticeType) o;

        if (type != that.type) return false;
        if (licenseType != that.licenseType) return false;
        if (subjectType != that.subjectType) return false;
        if (chapterId != that.chapterId) return false;
        return areaCode != null ? areaCode.equals(that.areaCode) : that.areaCode == null;
    }

    @Override
    public int hashCode() {
        int result = licenseType.hashCode();
        result = 31 * result + subjectType.hashCode();
        result = 31 * result + (areaCode != null ? areaCode.hashCode() : 0);
        result = 31 * result + type;
        result = 31 * result + (int)chapterId;
        return result;
    }


    public PracticeType copy(){
        PracticeType type = new PracticeType();
        type.chapterId = chapterId;
        type.areaCode = areaCode;
        type.licenseType = licenseType;
        type.subjectType = subjectType;
        type.type = this.type;
        return type;
    }

}
